package logic

import (
	"context"

	"github.com/comfygpt-backend-go/common/model"
	"github.com/comfygpt-backend-go/service/user-rpc/internal/svc"
	"github.com/comfygpt-backend-go/service/user-rpc/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type UpdateInfoLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUpdateInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateInfoLogic {
	return &UpdateInfoLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UpdateInfoLogic) UpdateInfo(in *user.UpdateInfoRequest) (*user.UpdateInfoResponse, error) {
	userInfo := &model.User{
		Id:                in.Id,
		Name:              in.Name,
		Email:             in.Email,
		Profile_image_url: in.ProfileImageUrl, // Assuming this field exists in the request
	}
	err := l.svcCtx.UserModel.Update(l.ctx, userInfo)
	if err != nil {
		return &user.UpdateInfoResponse{
			Success: false,
			Message: "Failed to update user information: " + err.Error(),
		}, err
	}
	return &user.UpdateInfoResponse{
		Success: true,
		Message: "User information updated successfully",
	}, nil

}
